<?php
$loader->requireOnce('includes/RadConnector/RadResultConnector.class.php');

class C_OutRadiology extends Controller {

	var $template_mod;
	var $_db;
	private $logger;

	public function __construct($template_mod = "general") {
		parent::Controller();
		$this->template_mod = $template_mod;
		$this->view->path 	= 'radiology';
		$this->logger = LoggerManager::getLogger('core.controllers.C_OutRadiology');
	}

    public function actionLoadRadResultAjax($recordId = 0) {
        $result = array(
            'error' => array(
                        'code' => CoreErrorCode::NORMAL,
                        'mess'=>''),
            'result'=> ''
        );

        if (isset($_GET['recordId'])) {
            $recordId = $_GET['recordId'];
        }

        $this->logger->info("Start action LoadRadResultAjax {recordId=$recordId}");
        try {

        	$medicalRecordObj = Celini::newOrdo('MedicalRecord');
        	$medicalRecordObj->setup($recordId);
        	$ticketId = $medicalRecordObj->get('ticket_id');

            $objConnector = new RadResultConnector();
            $result['result'] = $objConnector->loadRadResultView($ticketId);

        } catch (Exception $e){
            $result['error']['code'] = CoreErrorCode::COMMON_ERROR;
            $result['error']['mess'] = CoreErrorCode::getErrorMess(CoreErrorCode::COMMON_ERROR);
            $this->logger->error("Action LoadRadResultAjax fail. Error message:" . $e->getMessage());
        }
        $this->logger->info("Finish action LoadRadResultAjax {recordId=$recordId}");

        return json_encode($result);
    }
}
?>
